//
//  LCTabBarController.m
//  LazyCooking-OC
//
//  Created by 赵隆杰 on 2024/10/7.
//

#import "LCTabBarController.h"
#import "LCNavigationController.h"
#import "LCHomeViewController.h"
#import "LCCookbookViewController.h"
#import "LCSquareViewController.h"
#import "LCMineViewController.h"

@interface LCTabBarController ()

@end

@implementation LCTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    NSMutableArray *temp_array = [NSMutableArray array];
    for (NSDictionary *dict in [self tabbarData]) {
        LCNavigationController *nav = [self addNavWithDict:dict];
        if (nav) {
            [temp_array addObject:nav];
        }
    }
    self.viewControllers = [temp_array copy];
    self.tabBar.backgroundColor = [UIColor whiteColor];
    self.tabBar.tintColor = [UIColor purpleColor];//选中项颜色
//    self.tabBar.barTintColor = [UIColor whiteColor];//背景颜色
    self.tabBar.translucent = NO;//设置不透明
}

- (LCNavigationController *)addNavWithDict:(NSDictionary *)dict {
    Class classObject = NSClassFromString(dict[@"vc"]);
    if (!classObject) {
        return nil;
    }
    id object = [[classObject alloc] init];
    LCNavigationController *nav = [[LCNavigationController alloc] initWithRootViewController:object];
    nav.tabBarItem.title = dict[@"title"];
    nav.tabBarItem.image = [[UIImage imageNamed:dict[@"imageStr"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    nav.tabBarItem.selectedImage = [[UIImage imageNamed:dict[@"selectedImageStr"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    return nav;
}

- (NSArray *)tabbarData {
    return @[
        @{
            @"vc": @"LCHomeViewController",
            @"title": @"首页",
            @"imageStr": @"",
            @"selectedImageStr": @""
        },
        @{
            @"vc": @"LCCookbookViewController",
            @"title": @"菜谱",
            @"imageStr": @"",
            @"selectedImageStr": @""
        },
        @{
            @"vc": @"LCSquareViewController",
            @"title": @"广场",
            @"imageStr": @"",
            @"selectedImageStr": @""
        },
        @{
            @"vc": @"LCMineViewController",
            @"title": @"我的",
            @"imageStr": @"",
            @"selectedImageStr": @""
        },
    ];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
